package com.javabasic.algorithm.cometoj;

import java.util.Scanner;

public class 迫真字符串 {

    private static Scanner cin = new Scanner(System.in);

    public static void main(String[] args) {
        String str;
        str = cin.next();

        int one = 0, four = 0, five = 0;
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) == '1') {
                one++;
            } else if (str.charAt(i) == '4') {
                four++;
            } else if (str.charAt(i) == '5') {
                five++;
            }
        }
        int ans = 0;
        ans += Math.min(Math.min(one/3,four/2),five);
        System.out.println(ans);
    }

}
